# read a reconstructed file from pattern reconstruction software writen 
# by Prof. Thorsten Wiegand
# 
# filename: the path and filename of the reconstructed file
#
# return value: a conrespondence ppp object
#
# Author: Guochun Shen
# Data:   2011-12-20
# Project:spatial statistic
# Email:  shenguochun@gmail.com
###############################################################################



read_rec_file=function(filename){
	title=scan(filename,nlines=1,sep=" ")
	title=title[!is.na(title)]
	window=owin(c(title[1],title[2]),c(title[3],title[4]))
	nlines=title[length(title)]
	xy=scan(filename,nlines=1+nlines,sep=" ")
	xy=xy[-c(1:length(title))]
	xy=xy[!is.na(xy)]
	dim(xy)=c(4,length(xy)/4)
	xy=t(xy)[,1:2]
	data.ppp=ppp(x=xy[,1],y=xy[,2],window=window)
	return(data.ppp)
}

